package com.macquail.vaadin.ui.components.button;


import com.vaadin.ui.Button;
import com.vaadin.ui.Component;

public class FocusLosingButton extends Button implements Button.ClickListener{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = -3602073530800124985L;

	public FocusLosingButton() {
		super();
		addListener((Button.ClickListener)this);
	}

	public FocusLosingButton(String caption, ClickListener listener) {
		super(caption, listener);
		addListener((Button.ClickListener)this);
	}

	public FocusLosingButton(String caption, Object target, String methodName) {
		super(caption, target, methodName);
		addListener((Button.ClickListener)this);
	}

	public FocusLosingButton(String caption) {
		super(caption);
		addListener((Button.ClickListener)this);
	}

	@Override
	public void buttonClick(ClickEvent event) {
		Component parent = this.getParent();
		while (parent != null) {
			if(parent instanceof Component.Focusable) {
				((Component.Focusable) parent).focus();
				break;
			} else {
				parent = parent.getParent();
			}
		}
	}
}
	